﻿using System;
using System.Collections.Generic;
using System.Text;
using Peekaboo2008.model;
using System.Data;
using System.Data.SqlClient;
using Peekaboo2008.util;

namespace Peekaboo2008.dao
{
    class ThuChiDAO
    {
        public static void deleteByMaPhieuNhapXuat(String _MaPhieuNhapXuat)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = _MaPhieuNhapXuat;

            DataUtil.executeNonStore("sp_ThuChi_DeleteByMaPhieuNhapXuat", param);
        }
        public static String Chi_InsertNhapHangNhaCungCap(ThuChiModel model)
        {
            String returnID = "";
            int i = 0;
            SqlParameter[] param = new SqlParameter[7];
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = model.GhiChu;
            param[i] = new SqlParameter("So_tien", SqlDbType.Float);
            param[i++].Value = model.SoTien;
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = model.MaPhieuNhapXuat;
            param[i] = new SqlParameter("Noi_dung", SqlDbType.NVarChar);
            param[i++].Value = model.NoiDung;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = model.MaKhachHang;
            param[i] = new SqlParameter("Ma_nhan_vien", SqlDbType.Int);
            param[i++].Value = model.MaNhanVien;
            param[i] = new SqlParameter("OutID", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;

            DataUtil.executeNonStore("sp_ThuChi_Chi_InsertNhapHangNhaCungCap", param);

            returnID = param[i].Value.ToString();
            return returnID;
        }

        public static String Chi_InsertTienDuKhachMuaHang(ThuChiModel model)
        {
            String returnID = "";
            int i = 0;
            SqlParameter[] param = new SqlParameter[7];
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = model.GhiChu;
            param[i] = new SqlParameter("So_tien", SqlDbType.Float);
            param[i++].Value = model.SoTien;
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = model.MaPhieuNhapXuat;
            param[i] = new SqlParameter("Noi_dung", SqlDbType.NVarChar);
            param[i++].Value = model.NoiDung;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = model.MaKhachHang;
            param[i] = new SqlParameter("Ma_nhan_vien", SqlDbType.Int);
            param[i++].Value = model.MaNhanVien;
            param[i] = new SqlParameter("OutID", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;

            DataUtil.executeNonStore("sp_ThuChi_Chi_InsertTienDuKhachMuaHang", param);

            returnID = param[i].Value.ToString();
            return returnID;
        }

        public static String Chi_InsertKhachTraHang(ThuChiModel model)
        {
            String returnID = "";
            int i = 0;
            SqlParameter[] param = new SqlParameter[7];
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = model.GhiChu;
            param[i] = new SqlParameter("So_tien", SqlDbType.Float);
            param[i++].Value = model.SoTien;
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = model.MaPhieuNhapXuat;
            param[i] = new SqlParameter("Noi_dung", SqlDbType.NVarChar);
            param[i++].Value = model.NoiDung;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = model.MaKhachHang;
            param[i] = new SqlParameter("Ma_nhan_vien", SqlDbType.Int);
            param[i++].Value = model.MaNhanVien;
            param[i] = new SqlParameter("OutID", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;

            DataUtil.executeNonStore("sp_ThuChi_Chi_InsertKhachTraHang", param);

            returnID = param[i].Value.ToString();
            return returnID;
        }

        public static String Thu_InsertKhachTraKhiMuaHang(ThuChiModel model)
        {
            String returnID = "";
            int i = 0;
            SqlParameter[] param = new SqlParameter[7];
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = model.GhiChu;
            param[i] = new SqlParameter("So_tien", SqlDbType.Float);
            param[i++].Value = model.SoTien;
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = model.MaPhieuNhapXuat;
            param[i] = new SqlParameter("Noi_dung", SqlDbType.NVarChar);
            param[i++].Value = model.NoiDung;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = model.MaKhachHang;
            param[i] = new SqlParameter("Ma_nhan_vien", SqlDbType.Int);
            param[i++].Value = model.MaNhanVien;
            param[i] = new SqlParameter("OutID", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;

            DataUtil.executeNonStore("sp_ThuChi_Thu_InsertKhachTraKhiMuaHang", param);

            returnID = param[i].Value.ToString();
            return returnID;
        }

        public static String Thu_InsertTraHangNhaCungCap(ThuChiModel model)
        {
            String returnID = "";
            int i = 0;
            SqlParameter[] param = new SqlParameter[7];
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = model.GhiChu;
            param[i] = new SqlParameter("So_tien", SqlDbType.Float);
            param[i++].Value = model.SoTien;
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = model.MaPhieuNhapXuat;
            param[i] = new SqlParameter("Noi_dung", SqlDbType.NVarChar);
            param[i++].Value = model.NoiDung;
            param[i] = new SqlParameter("Ma_khach_hang", SqlDbType.Int);
            param[i++].Value = model.MaKhachHang;
            param[i] = new SqlParameter("Ma_nhan_vien", SqlDbType.Int);
            param[i++].Value = model.MaNhanVien;
            param[i] = new SqlParameter("OutID", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;

            DataUtil.executeNonStore("sp_ThuChi_Thu_InsertTraHangNhaCungCap", param);

            returnID = param[i].Value.ToString();
            return returnID;
        }

    }
}
